package main

import (
	"fmt"
	"io/ioutil"
)
import "log"
import "net/http"
import "strings"

type viewHandler struct{}

func ServeHTTP(w http.ResponseWriter, r *http.Request) {
	//path := r.URL.Path[1:]
	path := "房间.mp3"

	data, err := ioutil.ReadFile(string(path))

	if err != nil {
		log.Printf("Error with path %s: %v", path, err)
		w.WriteHeader(404)
		w.Write([]byte("404"))
	}

	if strings.HasSuffix(path, ".html") {
		w.Header().Add("Content-Type", "text/html")
	} else if strings.HasSuffix(path, ".mp3") {
		w.Header().Add("Content-Type", "audio/mp3")
	}

	w.Write(data)
}

func main() {
	http.HandleFunc("/", ServeHTTP)
	fmt.Println(":80 is listening")
	err:=http.ListenAndServe(":80", nil)
	if err!=nil{
		panic(err)
	}
}